import { request } from "./base";

/**
 * 用户登录接口成功结果
 */
export interface UserLoginResult {
  /** 用户id */
  uid: number;
  /** 昵称 */
  nickname: string;
  /** 头像 */
  avatar: string;
  /** 用户登录凭证 */
  token: string;
  /** token刷新凭证 */
  refresh_token: string;
}

/**
 * 用户手机号登录
 */
export const userMobileLogin = (data: { mobile: string; code: string }) => {
  return request<UserLoginResult>({
    url: "/pc/verify/login",
    method: "POST",
    data,
  });
};

/**
 * 刷新token
 */
export const reloadToken = (header: { Authorization: string }) => {
  return request<{
    token: string;
  }>({
    url: "/pc/refresh",
    method: "GET",
    header,
  });
};

/**
 * 获取用户信息
 */
export const getUserInfo = () => {
  return request<{
    user_info: Partial<UserLoginResult>;
  }>({
    url: "/pc/user/getUserInfo",
    method: "GET",
  });
};

/**
 * 编辑用户昵称
 * ---------
 * 用于演示未登录的跳转
 */
export const editUserNickname = (data: { nickname: string }) => {
  return request({
    url: "/pc/user/updateNickname",
    method: "POST",
    data,
  });
};
